package com.xycake.service;


import com.xycake.dao.UserMapper;
import com.xycake.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//登录，注册service
@Service
public class ClientService {

    @Autowired
    private UserMapper userMapper;

    public String regUser(User user){
        String msg="";
        User u=userMapper.selectByUsername(user.getUsername());
        if(u!=null){
            msg="当前用户已存在!";
        }else{
//            user.setRoleId(2);
            userMapper.insertSelective(user);
            msg="success";
        }
        return msg;
    }

    public User userLogin(User user) {
        User u = userMapper.selectByUsername(user.getUsername());
        if(u!=null&&u.getPassword().equals(user.getPassword())){
            return u;
        }else{
            return null;
        }
    }
}
